package com.wuhen.register;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView tv;
    private String str;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button bn = findViewById(R.id.btn);
        final Spinner sp =  findViewById(R.id.spinner2);
        sp.setOnItemSelectedListener(new OnItemSelectedListener()
                                     {
                                         @Override
                                         public void onItemSelected(AdapterView<?> parent, View view,
                                                                    int position, long id) {
                                             //拿到被选择项的值
                                             str = (String) sp.getSelectedItem();
                                         }

                                         @Override
                                         public void onNothingSelected(AdapterView<?> parent) {

                                         }
                                     });


        bn.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
            {
                EditText userNum = findViewById(R.id.user_num);
                EditText stNum = findViewById(R.id.st_num);
                EditText userName = findViewById(R.id.user_name);
                EditText userMail = findViewById(R.id.user_mail);
                EditText psw = findViewById(R.id.user_psw);
                EditText userPhone = findViewById(R.id.user_phone);
                User user=new User();
                user.setStNum(stNum.getText().toString());
                user.setUserNum(userNum.getText().toString());
                user.setUserName(userName.getText().toString());
                user.setUserMail(userMail.getText().toString());
                user.setUserPsw(psw.getText().toString());
                user.setXy(str);
                user.setUserPhone(userPhone.getText().toString());
              	Bundle data = new Bundle();
              	data.putSerializable("user", user);
              	//跳转
                Intent intent = new Intent(MainActivity.this,ResultActivity.class);
                intent.putExtras(data);
                startActivity(intent);
            }
        });

    }

}
